<?php

class Company
{    
    var $ID;
    var $company =  ''; 
	
    public function retrieve() 
    {
	require('../includes/DBConn.inc');
	$result = mysql_query("SELECT * from tblcompany");
	return $result;        
    }
    
     public function retrieveByName($searchVal) 
    {
	require('../includes/DBConn.inc');
	$result = mysql_query("SELECT * from tblcompany WHERE Company LIKE '%$searchVal%'");
	return $result;        
    }
    
    public function retrieveByID($id) 
    {
	require('../includes/DBConn.inc');
	$result = mysql_query("SELECT * from tblcompany WHERE ID=$id");
	$row = mysql_fetch_array($result);
	$this->company =  $row['Company'];
    }
    
    public function add()
    {       
      	require('../includes/DBConn.inc');
      	$query = "INSERT INTO tblcompany (company) VALUES ('$_POST[name]')";
      	     
      	$result = mysql_query($query) or die("Error: ".mysql_error());
      	return $result;
    }
    
    public function update($id)
    {
      	 require('../includes/DBConn.inc');
      	 $query = "UPDATE tblcompany SET company='$_POST[name]' 
      	 	   WHERE ID=$id";
      	 	   
      	 $result = mysql_query($query) or die("Error: ".mysql_error());
      	 return $result;
    }
    
    public function delete($id)
    {
    	 require('../includes/DBConn.inc');
         $result = mysql_query("DELETE FROM tblcompany WHERE id=$id") or die(mysql_error());   
    }
    
}
?>